@extends('shop::layouts.master')
@section('title')
    用户资料
@endsection
@section('tab')
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>个人资料</legend>
    </fieldset>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form" lay-filter="form_edit">
                <div class="layui-form-item"></div>
                <div class="layui-form-item">
                    <label  class="layui-form-label">
                        <span class="x-red">*</span>用户名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="username"  autocomplete="off" class="layui-input" disabled>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>手机号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="phone"  autocomplete="off" class="layui-input" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_alias" class="layui-form-label">
                        <span class="x-red"></span>上传头像</label>
                    <div class="layui-input-inline">
                        @if(empty($arr_data['avatar']['full_src']))
                            <img class="layui-upload-img upload_img" src="/admin/images/shop_user_default.png" height="150" width="150">

                        @else
                            <img class="layui-upload-img upload_img" src="{{$arr_data['avatar']['full_src']}}" height="150" width="150">

                        @endif
                        <input type="hidden" name="avatar" value="" lay-verify="head_img" id="img_url">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red"></span>昵称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="nickname" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red"></span>真实姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="realname"  autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red"></span>性别 </label>
                    <div class="layui-input-inline">
                        <input type="radio" name="sex" value="0" title="保密" checked="">
                        <input type="radio" name="sex" value="1" title="男">
                        <input type="radio" name="sex" value="2" title="女">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red"></span>生日</label>
                    <div class="layui-input-inline">
                        <input type="text" name="birthday" class="layui-input" id="test1" placeholder="年-月-日">
                    </div>
                </div>




                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <input type="hidden" name="id">
                    <button class="layui-btn" lay-filter="form_edit_submit" lay-submit="">修改</button>
                </div>
            </form>
        </div>
    </div>

@endsection


@section('tab_js')
    <script>
        layui.use(['form', 'layer','jquery','laydate'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer;

                var laydate = layui.laydate;
                //常规用法
                laydate.render({
                    elem: '#test1'
                });

                //监听提交
                form.on('submit(form_edit_submit)',
                    function(data) {
                        var $_data = data.field;
                        console.log($_data,'$_data');
                        var $_url = '{{route('shop_userinfo_update')}}';
                        $.ajax({
                            url:$_url,
                            type:'post',
                            data:$_data,
                            dataType : "json",
                            success:function(result){
                                if(result.state === 0){
                                    layer.msg(
                                        "修改成功",
                                        {time:500,icon: 6},
                                        function() {
                                            //关闭当前frame
                                            xadmin.close();

                                            // 可以对父窗口进行刷新
                                            xadmin.father_reload();

                                        });
                                }else{
                                    layer.msg(result.msg, {time:2000,icon: 5});
                                }

                            }});
                        return false;

                    });
                //表单初始赋值
                var data = {
                    id:"{{$arr_data['id']}}",
                    username:"{{$arr_data['username']}}",
                    phone:"{{$arr_data['phone']}}",
                    nickname:"{{$arr_data['nickname']}}",
                    realname:"{{$arr_data['realname']}}",
                    avatar:"{{$arr_data['avatar']['src']}}",
                    full_avatar:"{{$arr_data['avatar']['full_src']}}",
                    sex:"{{$arr_data['sex']}}",
                    birthday:"{{$arr_data['birthday']}}",
                };
                form.val('form_edit', data)

            });
    </script>
@endsection




